package com.adtec.base.cloud.security.jwt.utils;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Component
@Slf4j
public class GetUserId {
    public String getUsernameFromHeader() {
        String username;
        try {
            RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
            HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
            username = request.getHeader("userId");

//            Claims claims = getClaimsFromToken(jwtToken);
//            username = claims.getSubject();
            log.info("当前操作用户" + username);
        } catch (Exception e) {
            username = null;
        }
        return username;
    }
}
